<?php
session_start();
if (get_magic_quotes_gpc()){
	doStripSlashes($_GET);
	doStripSlashes($_POST);
	doStripslashes($_COOKIE);
}
function doStripSlashes(&$toDoArr){
	foreach ($toDoArr as $key => $value){
		$toDoArr[$key] = stripslashes($value);
	}
}

class NewBudget_Session {

	public static function get($property){
    	if(false==self::exist($property))	return false;
    	return $_SESSION["$property"];
	}

	public static function set($property,$newValue){
		$_SESSION["$property"]=$newValue;
	}

	public static function exist($property){
		return isset($_SESSION["$property"]);
	}

	public static function remove($property){
		unset($_SESSION["$property"]);
	}
	
	public static function isLogined(){
		return self::exist("userid");
	}
}
function checkIsLogin(){
	if(false==NewBudget_Session::get("userrole")){
		echo "0";//0表示没有登录或者登录过期
		exit;
	}
}
function showesg($reason="服务器错误，请联系管理员"){
	return Array("result"=>0,"reason"=>$reason);
}
function isAdmin(){
	return NewBudget_Session::get("userrole")=="admin";
}
function isGuest(){
	return NewBudget_Session::get("userrole")=="guest";
}
function isActor(){
	return NewBudget_Session::get("userrole")=="actor";
}
?>